package com.socket;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class Client {
	public static void main(String[] args) {
		Socket socket;
		BufferedReader br;
		PrintWriter pw;
		String str = "";
		try {
			
			socket = new Socket("localhost", 1002);
			//connect thanh cong =>
			
			//noi dung cua Client can gui den Server
			pw = new PrintWriter(socket.getOutputStream(), true);
			System.out.print("Nhap 1 chuoi phep toan can thuc hien: "); //co dang a+b, a-b, a*b hoac a/b
			br = new BufferedReader(new InputStreamReader(System.in));
			pw.println(br.readLine());
			//noi dung Server gui qua socket duoc doc va luu vao BufferedReader
			br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			while ((str = br.readLine()) != null) {
				System.out.println("Result returned from Server: " + str);
			}
			System.out.println("-");
			pw.close();
			System.out.println("--");
			br.close();
			System.out.println("---");
		} catch(UnknownHostException unknHostE) {
			unknHostE.printStackTrace();
		} catch(IOException ioE) {
			ioE.printStackTrace();			
		}
	}
}
